package org.flashbrighton.as3bots.views.ui
{
	import Box2D.Dynamics.b2Body;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.*;
	
	import org.flashbrighton.as3bots.models.GameModel;	

	public class ScoreBoard extends Sprite
	{
		private var _model:GameModel;
		private var _scoreText:TextField;
		
		
		public function ScoreBoard(model:GameModel)
		{
			_model = model;
			create();	
			_model.addEventListener(Event.CHANGE, update);			
		}
		
		
		private function create():void
		{
			_scoreText = new TextField();
			_scoreText.defaultTextFormat = new TextFormat("Arial", 12, 0xFFFFFF);
			_scoreText.autoSize = TextFieldAutoSize.LEFT;
			addChild(_scoreText);
		}
		
		
		private function update(e:Event):void
		{
			var scores:String = "";
			var colour:String;
			
			for each (var bot:b2Body in _model.botList)
			{
				scores += bot.m_userData.name + ":" + bot.m_userData.energy + "\n";
				//colour = bot._colour.toString(16);
				//scores += "<font color='#" + colour +"' face='Arial'>" + bot.name + " : " + bot.energy + "</font>\n";
			}
			
			_scoreText.htmlText = scores;
		}

	}
}